package com.supermap.originTest2;


import com.supermap.data.*;


public class TestUpdateByJoinItem {

    /**
     * 程序入口点
     * The entrance of the programme.
     */
    public static void main(String[] args) {

		Workspace workspace = new Workspace();
		WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(
				"E:\\MapData\\202404\\test\\WorkSpace.smwu");
		conInfo.setType(WorkspaceType.SMWU);
		workspace.open(conInfo);
		Datasource d = workspace.getDatasources().get("geotest");
		DatasetVector datasetVector = (DatasetVector)d.getDatasets().get("NewPoint");


		JoinItems joinItems = new JoinItems();
		JoinItem joinItem = new JoinItem();
		joinItem.setJoinType(JoinType.LEFTJOIN);
		joinItem.setForeignTable("NewPoint_1");
		joinItem.setName("myJoinItem");
		joinItem.setJoinFilter("NewPoint.SmID=NewPoint_1.SmID");
		joinItems.add(joinItem);


		QueryParameter queryParameter = new QueryParameter();
		queryParameter.setCursorType(CursorType.STATIC);
		queryParameter.setJoinItems(joinItems);
		queryParameter.setResultFields(new String[]{"NewPoint_1.col_1 as col_1","NewPoint.col","NewPoint.SmX"});
		Recordset recordset = datasetVector.query(queryParameter);

		



		//返回false，代表更新失败
//		System.out.println(datasetVector.updateField("col_1","NewPoint_1.col_1",null,joinItems));
		System.out.println(recordset.getRecordCount());
		System.out.println(recordset.getFieldInfos().getCount());
		System.out.println(recordset.getFieldInfos().get(1).getName());
		System.out.println(recordset.getFieldInfos().get(2).getName());
		System.out.println(recordset.getFieldInfos().get(0).getName());
		System.out.println(recordset.getFieldInfos().get(3).getName());
		for(Integer key:recordset.getAllFeatures().keySet()){
			System.out.println(recordset.getAllFeatures().get(key).getString(1));
			System.out.println(recordset.getAllFeatures().get(key).getString("col_1"));
		}




		workspace.save();
		workspace.dispose();





	}


}  

